const express = require('express');
const cors = require('cors');
const poiRoutes = require('./routes/poi');
const path = require('path');
require('dotenv').config();

const app = express();

// 允许来自前端位置的跨域请求
app.use(cors({
  origin: 'http://127.0.0.1:3000',   // 或者用 '*' 允许所有
  methods: ['GET','POST','PUT','DELETE','OPTIONS'],
  allowedHeaders: ['Content-Type','Authorization']
}));

app.use(express.json());

// 路由
app.use('/api', poiRoutes);

const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
  console.log(`后端服务已启动 http://localhost:${PORT}`);
});